/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制
*/
package co.yixiang.modules.shop.service.impl;

import co.yixiang.modules.shop.domain.YxStoreOnline;
import co.yixiang.common.service.impl.BaseServiceImpl;
import lombok.AllArgsConstructor;
import co.yixiang.dozer.service.IGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import co.yixiang.modules.shop.service.YxStoreOnlineService;
import co.yixiang.modules.shop.service.dto.YxStoreOnlineDto;
import co.yixiang.modules.shop.service.dto.YxStoreOnlineQueryCriteria;
import co.yixiang.modules.shop.service.mapper.YxStoreOnlineMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;

/**
* @author chajiu
* @date 2021-04-25
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "yxStoreOnline")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxStoreOnlineServiceImpl extends BaseServiceImpl
<YxStoreOnlineMapper, YxStoreOnline> implements YxStoreOnlineService {

private final IGenerator generator;

@Override
//@Cacheable
public Map
<String, Object> queryAll(YxStoreOnlineQueryCriteria criteria, Pageable pageable) {
getPage(pageable);
PageInfo<YxStoreOnline> page = new PageInfo<>(queryAll(criteria));
Map
<String, Object> map = new LinkedHashMap<>(2);
map.put("content", generator.convert(page.getList(), YxStoreOnlineDto.class));
map.put("totalElements", page.getTotal());
return map;
}


@Override
//@Cacheable
public List<YxStoreOnline> queryAll(YxStoreOnlineQueryCriteria criteria){
return baseMapper.selectList(QueryHelpPlus.getPredicate(YxStoreOnline.class, criteria));
}


@Override
public void download(List
<YxStoreOnlineDto> all, HttpServletResponse response) throws IOException {
    List
    <Map
    <String
    , Object>> list = new ArrayList<>();
    for (YxStoreOnlineDto yxStoreOnline : all) {
    Map
    <String
    ,Object> map = new LinkedHashMap<>();
                map.put("店铺名称", yxStoreOnline.getName());
                map.put("店铺logo", yxStoreOnline.getImage());
                map.put("店铺手机", yxStoreOnline.getPhone());
                map.put("门店状态：正常、封禁、暂停", yxStoreOnline.getStatus());
                map.put("状态变化时间", yxStoreOnline.getStatusChangeTime());
                map.put("封禁时间（天）", yxStoreOnline.getBanDay());
                map.put("门店入驻时间", yxStoreOnline.getOnlineTime());
                map.put("拥有者ID", yxStoreOnline.getOwnerId());
                map.put("拥有者姓名", yxStoreOnline.getOwnerName());
                map.put("店铺ID", yxStoreOnline.getShopId());
                map.put("店铺介绍", yxStoreOnline.getDescription());
                map.put("发货地址", yxStoreOnline.getSendAddress());
                map.put("退货地址", yxStoreOnline.getBackAddress());
                map.put("退货联系人", yxStoreOnline.getBackPeople());
                map.put("退货人手机", yxStoreOnline.getBackPhone());
                map.put("认证信息", yxStoreOnline.getConfirmMsg());
    list.add(map);
    }
    FileUtil.downloadExcel(list, response);
    }
    }
